package pso;

public class BoundaryHandlerRandom implements BoundaryHandler {
	private PointGenerator startingPointGenerator, startingVelocityGenerator;
	private Point lowerBound, upperBound;
	public BoundaryHandlerRandom(
			Point lowerBound, Point upperBound,
			PointGenerator startingPointGenerator,
			PointGenerator startingVelocityGenerator) {
		this.startingPointGenerator = startingPointGenerator;
		this.startingVelocityGenerator = startingVelocityGenerator;
		this.lowerBound = lowerBound;
		this.upperBound = upperBound;
	}

	@Override
	public void applyBoundaryHandling(Particle p) {
		Point pos = p.getPosition();
		int dim = pos.getDimension();
		for(int i = 0; i < dim; i++){
			double x = pos.getCoordinate(i);
			double xlo = lowerBound.getCoordinate(i);
			double xhi = upperBound.getCoordinate(i);
			if(x < xlo || x > xhi){
				p.setPosition(startingPointGenerator.nextPoint());
				p.setVelocity(startingVelocityGenerator.nextPoint());
				return;
			}
		}
	}

}
/*


public BoundaryHandlerBounce(){
}
@Override
public void applyBoundaryHandling(Particle p) {

}
*/